package com.tanhua.dubbo.api;

import com.tanhua.dubbo.utils.IdWorker;
import com.tanhua.model.domain.FocusUser;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;


@DubboService
public class FocusUserApiImpl implements FocusUserApi{
    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 保存关注用户信息
     * @param focusUser
     */
    @Override
    public void save(FocusUser focusUser) {
        //保存数据
        mongoTemplate.save(focusUser);
    }

    /**
     * 取消注用户信息
     * @param uid
     * @param userId
     */
    @Override
    public void delete(Long uid, Long userId) {
        //构造查询条件
        Query query = Query.query(Criteria.where("userId").is(userId).and("attentionId").is(uid));
        //删除数据
        mongoTemplate.remove(query,FocusUser.class);
    }

}
